const { mysql } = require('../qcloud')

module.exports = async ctx => {

  var content = ctx.request.url;

  var openId = content.substring(content.indexOf('openId') + 7, content.indexOf('nickname')-1);
  var nickname = content.substring(content.indexOf('nickname') + 9, content.indexOf('province') - 1);
  var province = content.substring(content.indexOf('province') + 9, content.indexOf('gender') - 1);
  var gender = content.substring(content.indexOf('gender') + 7, content.indexOf('country') - 1);
  var country = content.substring(content.indexOf('country') + 8, content.indexOf('city') - 1);
  var city = content.substring(content.indexOf('city') + 5, content.indexOf('avatarUrl') - 1);
  var avatarUrl = content.substring(content.indexOf('avatarUrl') + 10);
  
  // 插入消息
  var myDate = new Date();
  var userinfo = {
    openId: openId,
    nickname: decodeURI(nickname),
    gender: gender,
    country: decodeURI(country),
    province: province,
    city: city,
    avatarUrl: avatarUrl,
  }

  await mysql("userinfo").insert(userinfo);

  ctx.state.data = ctx

}